<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<html lang="zh-cn" style="height: 100%">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <title><?=VIEW_TITLE?></title>
    <link href="<?php echo base_url('/assets/bs/'); ?>css/bootstrap.min.css" rel="stylesheet">
    <link href="<?php echo base_url('/assets/css/'); ?>my_common.css" rel="stylesheet">
    <script src="http://cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="http://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>

	<style>
		@media only screen and (max-width: 768px){
			.oneCell{
    		 		height:300px;
    		 		margin-bottom: 80px;
    		 	}
    		 	
    		 	.cellMargin{
    		 		margin-top:30px;
    		 		margin-bottom:30px;
    		 	}
    		 	
    		 	
		}
	</style>
</head>
<body>
<?php
$this->load->view('admin_header.php');
?>
<div class="container-fluid">
    <div id="main_div" style="position:relative;margin: 0 auto 10px auto;">
        <div class="row">
            <!--这里是原文内容-->
            <div class="col-sm-6 col-md-6 col-xs-11">
                <div class="oneCell" id="text_div" style="overflow-x: hidden;margin: 0 auto 10px auto;">
                    <div class="article_title">
                        <h3 style="text-align: center;"><?php echo $original_article['title']; ?></h3>
                    </div>
                    <div class="article_content"><?php echo $original_article['article_html']; ?></div>
                    <div style="text-align: right;">
                        字数:<?php echo iconv_strlen($original_article['article_text'], 'utf-8'); ?>
                    </div>
                    <div class="article_url" style="background-color: #f5f5f5;line-height: 40px;padding-left: 10px">
                        原文链接:<a
                            href="<?php echo $original_article['url']; ?>"><?php echo $original_article['url']; ?></a>
                    </div>
                </div>
            </div>
          
            <!--这里是校对编辑内容-->
            <div class="col-sm-6 col-md-6 col-xs-11" style="<?php if ($user_id == $proofread_info['proofread_user_id'] && $article_manager_info['is_proofreaded'] != 2) {
                     //&& $article_manager_info['is_proofreaded'] != 2
                     echo 'display:block';
                 } else {
                     echo 'display:none';
                 } ?>">
                <div class="" style="overflow-x: hidden;margin: 50px auto 10px auto;">
                    <input type="text" class="form-control" placeholder="请输入文章标题" id="title"
                           value="<?php echo $proofread_info['title']; ?>">
                </div>
                <div style="overflow-x: hidden;margin: 0 auto 10px auto;display: none;">
                    <input type="text" class="form-control" placeholder="请输入原文链接(如果无,可留空)" id="url"
                           value="<?php echo $original_article['url']; ?>">
                </div>
                <?php if ($article_manager_info['is_proofreaded'] != 2) { ?>
                    <div style="overflow-x: hidden;margin: 0 auto 10px auto;">
                        <input type="text" class="form-control" placeholder="翻译得分(保存可留空)" id="score"
                               value="<?php if ($proofread_info['score'] > 0) {
                                   echo $proofread_info['score'];
                               } ?>">
                    </div>
                <?php } else { ?>
                    <div style="overflow: scroll;overflow-x: hidden;margin: 0 auto 10px auto;">
                        <input type="text" class="form-control" placeholder="翻译得分(保存可留空)" id="score"
                               value="<?php echo $proofread_info['score']; ?>" readonly="readonly">
                    </div>
                <?php } ?>

                <div class="oneCell" style="overflow-x: hidden;margin: 0 auto 10px auto;">
                    <script id="container" name="content" type="text/plain">
                    </script>
                </div>
            </div>
            
            <!--这里是校对输出内容-->
            <div class="col-sm-6 col-md-6 col-xs-11"
            	 style="<?php
                 if ($article_manager_info['is_proofreaded'] != 2) {
//                 if ($article_manager_info['is_proofreaded'] != 2 || $user_id == $proofread_info['proofread_user_id']) {
                     echo 'display:none';
                 } ?>">
                <div class="oneCell" id="text_div" style="overflow-x: hidden;margin: 0 auto 10px auto;">
                    <div class="article_title">
                        <h3 style="text-align: center;"><?php echo $proofread_info['title']; ?></h3>
                    </div>
                    <div class="article_content"><?php echo $proofread_info['article_html']; ?></div>
                    <div style="text-align: right;">
                        <?php echo '字数:' . $text_number . '<br>评分:' . $proofread_info['score']; ?>
                    </div>
                    <div class="article_url" style="background-color: #f5f5f5;line-height: 40px;padding-left: 10px">
                        原文链接:<a
                            href="<?php echo $original_article['url']; ?>"><?php echo $original_article['url']; ?></a>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <div class="hidden-xs"  id="btn_group"
         style="position:fixed;top: 200px;z-index: 99999;
         <?php
         //                  if ($article_manager_info['is_proofreaded'] == 2 && $user_id != $proofread_info['proofread_user_id']) {
         if ($article_manager_info['is_proofreaded'] == 2) {
             echo 'display:none';
         } ?>">
        <div>
            <button type="button" class="btn btn-default btn-sm" onclick="doProofread(1)">
                <span class="glyphicon glyphicon-floppy-disk"></span> 保存
            </button>
        </div>
        <div style="margin-top: 10px;">
            <button type="button" class="btn btn-default btn-sm" onclick="faBiaoQueRen()">
                <span class="glyphicon glyphicon-open"></span> 提交
            </button>
        </div>
    </div>
    <div  class="visible-xs" style="margin-top:10px;margin-bottom: 10px;"
    	         <?php
         //if ($article_manager_info['is_proofreaded'] == 2 && $user_id != $proofread_info['proofread_user_id']) {
         if ($article_manager_info['is_proofreaded'] == 2) {
             echo 'display:none';
         } ?>">
     
            <button type="button" class="btn btn-default" onclick="doProofread(1)">
                <span class="glyphicon glyphicon-floppy-disk"></span> 保存
            </button>
        
        
            <button type="button" class="btn btn-default" onclick="faBiaoQueRen()">
                <span class="glyphicon glyphicon-open"></span> 提交
            </button>
        
    </div>
    <div class="container-fluid"
         style="overflow:hidden;margin-bottom:50px;display: <?php if ($_SESSION['user_type'] == 4) {
             echo 'block';
         } else {
             echo 'none';
         } ?>">
        <div class="row">
            <div class="col-sm-6">
                <?php if (empty($article_manager_info['yunying_title'])) { ?>
                    <div class="input-group">
                        <input type="text" class="form-control" id="yunyingtitle" placeholder="填写运营题目">
                      <span class="input-group-btn">
                        <button class="btn btn-default" type="button" onclick="yunYingTitle()">确认运营题目</button>
                      </span>
                    </div>
                <?php } else { ?>
                    <div class="input-group">
                        <input type="text" class="form-control" id="yunyingtitle" placeholder="填写运营题目"
                               value="<?php echo $article_manager_info['yunying_title']; ?>">
                      <span class="input-group-btn">
                        <button class="btn btn-default" type="button" onclick="yunYingTitle()">确认运营题目</button>
                      </span>
                    </div>
                    <!--                    <span style="line-height: 34px;">--><?php //echo '运营题目:' . $article_manager_info['yunying_title']; ?><!--</span>-->
                <?php } ?>
            </div>
            <div class="col-sm-6">
                <?php if (empty($article_manager_info['read_number'])) { ?>
                    <div class="input-group">
                        <input type="text" class="form-control" id="readnumber" placeholder="填写奖励，单位为大洋">
                      <span class="input-group-btn">
                        <button class="btn btn-default" type="button" onclick="readNumber()">确认奖励量</button>
                      </span>
                    </div>
                <?php } else { ?>
                    <span style="line-height: 34px;"><?php echo '阅读量:' . $article_manager_info['read_number']; ?></span>
                <?php } ?>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="fabiao_model">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title">确认提交</h4>
            </div>
            <div class="modal-body">
                <div>
                    注意:确认提交后校对和评分不能再修改!
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="doProofread(2)">确认</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script src="<?php echo base_url('/assets/bs/'); ?>js/bootstrap.min.js"></script>
<script type="text/javascript" src="<?php echo base_url('/assets/ueditor/ueditor.config.js?v=') . time(); ?>"></script>
<script type="text/javascript" src="<?php echo base_url('/assets/ueditor/'); ?>ueditor.all.js"></script>
<script type="text/javascript">
    var w_width = document.documentElement.clientWidth;
    var w_height = document.documentElement.clientHeight;
    var is_proofreaded = "<?php echo $article_manager_info['is_proofreaded']; ?>";
    //    $('#text_div').css('height', w_height - 90 + 'px');
    var right = 10;
    //    if (right <= 0) {
    //        right = 10;
    //    }
    $('#btn_group').css('right', right);
    $('#btn_group').css('top', w_height - 200);

    var ue = UE.getEditor('container', {
        initialFrameHeight: w_height - 260,
        enableAutoSave: false, //禁止自动保存
        autoSyncData: false,//自动同步编辑器要提交的数据
        toolbars: [
            [
                'undo', //撤销
                'strikethrough', //删除线
                'pasteplain', //纯文本粘贴模式
                'removeformat', //清除格式
                'fontfamily', //字体
                'fontsize', //字号
                //'paragraph', //段落格式
                'unlink', //取消链接
                'link', //超链接
                'fullscreen', //全屏
                //'rowspacingtop', //段前距
                //'rowspacingbottom', //段后距
                //'lineheight', //行间距
                'forecolor', //字体颜色
            ]
        ]
    });
    ue.ready(function () {
        ue.setContent('<?php echo str_replace(array("'"),"\'",str_replace(array("\r\n","\r","\n"),"",$proofread_info["article_html"])) ?>'); 
        
    });
    function faBiaoQueRen() {
        $("#fabiao_model").modal("show");
    }
    function doProofread(status) {
        var html = ue.getContent();
        var text = ue.getContentTxt();
        var title = $('#title').val();
        var url = $('#url').val();
        var score = $('#score').val();
        if (title == '') {
            alert('标题不能留空!');
            return false;
        }
        if (html == '' || text == '') {
            alert('内容不能留空!');
            return false;
        }
        if (status == 2 && score == '') {
            alert('请评分再提交!');
            return false;
        }
        if (score != '') {
            if (isNaN(score)) {
                alert('请正确填写分数');
                return false;
            }
            if (score > 5) {
                alert("评分超过5分,请重新评分!");
                return false;
            }
            if (parseInt(score) != score) {
                alert("请输入整数!");
                return false;
            }
        }
        if (is_proofreaded == 2) {
            status = 2;
        }
        $.ajax({
            url: '<?php echo site_url('/taskworker/proofreadSave')?>',
            type: 'post',
            dataType: 'json',
            data: {
                html: html,
                text: text,
                title: title,
                manager_id:<?php echo $manager_id;?>,
                proofread_id:<?php echo $proofread_info['id'];?>,
                is_received: <?php echo $article_manager_info['is_received'];?>,
                translation_user_id: <?php echo $translation_info['translation_user_id'];?>,
                status: status,
                score: score,
                url: url
            },
            success: function (data) {
                if (data == 'success' && status == 1) {
                    alert('保存成功!');
                }
                if (data == 'success' && status == 2) {
                    alert('提交成功!');
                    window.location.reload();
                }
            }
        });
    }

    function autoSave() {
        var html = ue.getContent();
        var text = ue.getContentTxt();
        var title = $('#title').val();
        var url = $('#url').val();
        var score = $('#score').val();
        if (title == '') {
            return false;
        }
        if (html == '' || text == '') {
            return false;
        }

        if (score != '') {
            if (isNaN(score)) {
                alert('请正确填写分数');
                return false;
            }
            if (score > 5) {
                alert("评分超过5分,请重新评分!");
                return false;
            }
            if (parseInt(score) != score) {
                alert("请输入整数!");
                return false;
            }
        }
        $.ajax({
            url: '<?php echo site_url('/taskworker/proofreadSave')?>',
            type: 'post',
            dataType: 'json',
            data: {
                html: html,
                text: text,
                title: title,
                manager_id:<?php echo $manager_id;?>,
                proofread_id:<?php echo $proofread_info['id'];?>,
                is_received: <?php echo $article_manager_info['is_received'];?>,
                translation_user_id: <?php echo $translation_info['translation_user_id'];?>,
                status: 1,
                score: score,
                url: url
            },
            success: function (data) {
                if (data == 'success' && status == 1) {
                    console.log('auto save success !');
                }
            }
        });
    }

    if (is_proofreaded != 2) {
        var int = self.setInterval("autoSave()", 8000);
    }

    function readNumber() {
        var readnumber = $("#readnumber").val();
        if (readnumber == '' || isNaN(readnumber)) {
            alert('阅读量必须为整数!');
            return false;
        }
        $.ajax({
            url: '<?php echo site_url("staff/writeReadNumber");?>',
            type: 'post',
            dataType: 'json',
            data: {
                readnumber: readnumber,
                textnumber: <?php echo $text_number;?>,
                manager_id:<?php echo $article_manager_info['id'];?>,
                score:<?php echo $proofread_info['score'];?>,
                translation_user_id: <?php echo $translation_info['translation_user_id']?>
            },
            success: function (data) {
                if (data == 'success') {
                    location.reload();
                    return false;
                } else {
                    alert('Error:系统错误,刷新重试!');
                    return false;
                }
            }
        });
    }
    function yunYingTitle() {
        var yunyingtitle = $("#yunyingtitle").val();
        if (yunyingtitle == '') {
            alert('运营题目不能为空!');
            return false;
        }
        $.ajax({
            url: '<?php echo site_url("staff/writeYunYinGTitle");?>',
            type: 'post',
            dataType: 'json',
            data: {
                manager_id:<?php echo $article_manager_info['id'];?>,
                yunyingtitle: yunyingtitle
            },
            success: function (data) {
                location.reload();
                return false;
            }
        });
    }

    function logout() {
        $.ajax({
            url: '<?php echo site_url("admin/logout");?>',
            type: 'post',
            dataType: '',
            data: '',
            success: function (data) {
                window.location.href = '<?php echo site_url("admin/login");?>';
                return false;
            }
        });
    }
</script>
</body>
</html>
